package com.ruoyi.system.service.impl;

import java.util.Collections;
import java.util.List;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.BusSupplieeInfoMapper;
import com.ruoyi.system.domain.BusSupplieeInfo;
import com.ruoyi.system.service.IBusSupplieeInfoService;
import org.springframework.util.CollectionUtils;

/**
 * 供应商信息Service业务层处理
 *
 * @author hst
 * @date 2021-12-15
 */
@Service
public class BusSupplieeInfoServiceImpl implements IBusSupplieeInfoService
{
    @Autowired
    private BusSupplieeInfoMapper busSupplieeInfoMapper;

    /**
     * 查询供应商信息
     *
     * @param supplierId 供应商信息主键
     * @return 供应商信息
     */
    @Override
    public BusSupplieeInfo selectBusSupplieeInfoBySupplierId(Long supplierId)
    {
        return busSupplieeInfoMapper.selectBusSupplieeInfoBySupplierId(supplierId);
    }

    /**
     * 查询供应商信息列表
     *
     * @param busSupplieeInfo 供应商信息
     * @return 供应商信息
     */
    @Override
    public List<BusSupplieeInfo> selectBusSupplieeInfoList(BusSupplieeInfo busSupplieeInfo)
    {
        return busSupplieeInfoMapper.selectBusSupplieeInfoList(busSupplieeInfo);
    }

    /**
     * 新增供应商信息
     *
     * @param busSupplieeInfo 供应商信息
     * @return 结果
     */
    @Override
    public int insertBusSupplieeInfo(BusSupplieeInfo busSupplieeInfo)
    {
        BusSupplieeInfo tmp = new BusSupplieeInfo();
        tmp.setUserPhone(busSupplieeInfo.getUserPhone());
        List<BusSupplieeInfo> busSupplieeInfos = busSupplieeInfoMapper.selectBusSupplieeInfoList(tmp);
        if (!CollectionUtils.isEmpty(busSupplieeInfos)) {
            throw new ServiceException("手机号已存在，请不要重复创建！");
        }


        busSupplieeInfo.setCreateTime(DateUtils.getNowDate());
        return busSupplieeInfoMapper.insertBusSupplieeInfo(busSupplieeInfo);
    }

    /**
     * 修改供应商信息
     *
     * @param busSupplieeInfo 供应商信息
     * @return 结果
     */
    @Override
    public int updateBusSupplieeInfo(BusSupplieeInfo busSupplieeInfo)
    {
        busSupplieeInfo.setUpdateTime(DateUtils.getNowDate());
        return busSupplieeInfoMapper.updateBusSupplieeInfo(busSupplieeInfo);
    }

    /**
     * 批量删除供应商信息
     *
     * @param supplierIds 需要删除的供应商信息主键
     * @return 结果
     */
    @Override
    public int deleteBusSupplieeInfoBySupplierIds(Long[] supplierIds)
    {
        return busSupplieeInfoMapper.deleteBusSupplieeInfoBySupplierIds(supplierIds);
    }

    /**
     * 删除供应商信息信息
     *
     * @param supplierId 供应商信息主键
     * @return 结果
     */
    @Override
    public int deleteBusSupplieeInfoBySupplierId(Long supplierId)
    {
        return busSupplieeInfoMapper.deleteBusSupplieeInfoBySupplierId(supplierId);
    }
}
